
def i2r(n):
  num_list =   [1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000]
  roman_list = ["I", "IV", "V", "IX", "X", "XL", "L", "XC", "C", "CD", "D", "CM", "M"]
  result = ""

  # range(0, 10) 0 1 2 3 4 5 ...
  # range(10, 0, -1) 10 9 8 7 ... 1
  # 2994
  # num_list[i] = 1000
  # quotient = 2994 // 1000 = 2
  # result = "MM"
  # n = n % num_list[i] = 2994 % 1000 = 994
  #
  # n = 994
  # num_list[i] = 900
  # quotient = 994 // 900 = 1
  # result = "MM" + "CM"
  # n = 994 % 900 = 94
  #
  # n = 94
  # num_list[i] = 500
  # quotient = 94 // 500 = 0
  # n = n % num_list[i] = 94 % 500 = 94
  # ...
  # n = 94
  # num_list[i] = 90
  # quotient = 94 // 90 = 1
  # result = "MM" + "CM" + "XL"
  # n = 94 % 90 = 4
  # ...
  # n = 4
  # num_list[i] = 4
  # quotient = 4 // 4 = 1
  # result = "MM" + "CM" + "XL" + "IV"
  # n = 4 % 4 = 0
  #
  # n = 0
  for i in range(len(num_list) - 1, 0, -1):

    quotient = n // num_list[i]

    for j in range(0, quotient):
      result += roman_list[i]
    
    n %= num_list[i]

  return result

print(i2r(1994))
